package springIOC.IOC_XML.handler;

import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ListBeanResultSetHandler<T> implements ResultSetHandler<List<T>> {

    Class<T> classMap;

    public ListBeanResultSetHandler(Class<T> clazz){
        this.classMap=clazz;
    }

    @Override
    public List<T> handle(ResultSet resultSet) throws SQLException {
        List<T> list=new ArrayList<>();
        ResultSetUtil util=new ResultSetUtil();
        while (resultSet.next()){
            list.add(util.resultSetToBean(classMap,resultSet));
        }
        return list;
    }
}
